<?php

use yii\helpers\Html;
use yii\helpers\Url;
use backend\widgets\GridView;
use yii\widgets\Breadcrumbs;
use yii\bootstrap\Modal;
use backend\models\service\AdminService as Admin;
use backend\models\service\TweetService as Tweet;
$this->title = '合作方详情';
Modal::begin([
    'id' => 'common-modal',
    'header' => '<h4 class="modal-title"></h4>',
    'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',
]);


$js = <<<JS
$(".modaldialog").click(function(){ 
        aUrl = $(this).attr('data-url');
        aTitle = $(this).attr('data-title');
        $($(this).attr('data-target')+" .modal-title").text(aTitle);
        $($(this).attr('data-target')).modal("show")
             .find(".modal-body")
             .load(aUrl); 
        return false;
   }); 
JS;
$this->registerJs($js);

Modal::end();
?>

<div class="RightCenter clear">

    <div class="RightTime">
        <div class="Time">
            <h3>合作方账号列表：<?php echo $data['username']; ?></h3>
        </div>
    </div>
    <p style="margin:30px;"> <?php
        echo Html::a('新建渠道', 'create-channel', [
            'id' => 'create-channel',
            'class' => 'modaldialog btn btn-success',
            'data-toggle' => 'modal',
            'data-url' => Url::toRoute(['create-channel']),
            'data-title' => '新建渠道',
            'data-target' => '#common-modal',
        ]);
        ?>
    </p>
     <div class="Read_date" style="margin-top:20px;margin-bottom: 5px;height:60px;">
        <ul>
            <li class="Read_LisJ" style="margin-top:12.5px;">
                <div class="Seek">
                    <input type="text" class="form-control AppIN" id="exampleInputAmount" placeholder="搜索渠道名称" value="<?php echo isset($search['name']) ? $search['name'] : '';?>">
                    <button type="button" class="btn btn-primary SS">搜索</button>
                </div>
            </li>
            <div class="SX clear">
                筛选:
                 <select id="op">
                    <option value="">全部渠道</option>
                    <?php foreach($channels as $c):?>
                        <option <?php echo isset($search['cid']) && $c['id'] == $search['cid'] ? 'selected = "selected"' : '';?> value="<?php echo $c['id'];?>"><?php echo $c['username'];?></option>
                    <?php endforeach;?>
                </select>
                <button class="btn btn-primary czS" type="button">
                    重置
                </button>
            </div>
        </ul>
    </div>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            [
                'label' => '渠道信息',
                'format' => 'raw',
                'headerOptions' => ['width' => 80],
                'value' => function($data) {
                    return $data->username . '</br>' . $data->id ;
                }
            ],
            [
//                'attribute' => 'username',
                'label' => '推文数量',
                'headerOptions' => ['width' => 30],
                'value' => function($data) {
                    $a = new Tweet();
                    return $a->getTweetNums($data->id);
                }
            ],
            [
                'attribute' => 'remark',
                'label' => '备注',
                'headerOptions' => ['width' => 100],
            ],
            [
                'attribute' => 'create_time',
                'label' => '创建时间',
                'headerOptions' => ['width' => 80],
            ],
            [
                'class' => \yii\grid\ActionColumn::className(),
                'header' => '操作',
                'headerOptions' => ['width' => 100],
                'contentOptions' => ['class' => 'action-link'],
                'template' => '{update-channel} {del-channel}',
                'buttons' => [
                    'update-channel' => function ($url, $model, $key) {
                        return Html::a('编辑', $url, [
                             'id' => 'update-channel',
                             'class' => 'modaldialog',
                             'data-toggle' => 'modal',
                             'data-url' => Url::toRoute($url),
                             'data-title' => '编辑',
                             'data-target' => '#common-modal',
                         ])." ";
                    },
                    'del-channel' => function ($url, $model, $key) {
                        return Html::a('删除', $url, [
                                    'data' => [
                                        'confirm' => '确定/删除？',
                                        'method' => 'post',
                                    ],
                        ]);
                    },
                ],
            ],
        ],
    ]);
    ?>
</div>
<script>
    $(".SS").click(function(){
        var name = $("#exampleInputAmount").val();
        var cid = $("#op").val();
        if(name != '' || cid != ''){
            location.href="/admin/view?name="+name+"&cid="+cid+"&id="+<?php echo $search['id'];?>
        }
    });
    
    $(".czS").click(function(){
        location.href="/admin/view?id="+<?php echo $search['id'];?>
    });
</script>